package com.oocl.batchdatav2.formatter.impl;

import java.util.Set;

import com.oocl.batchdatav2.formatter.DataFormatter;
import com.oocl.batchdatav2.pojo.Customer;

public class DataFormatterImpl implements DataFormatter {

	@Override
	public StringBuilder getCustomersAsString(Set<Customer> customerList, String format) {
		switch (format) {
		case "xml":
			return getCustomersAsXML(customerList);
		case "line":
			return getCustomersAsLine(customerList);
		default:
			return null;
		}
	}
	
	private StringBuilder getCustomersAsXML(Set<Customer> customerList) {
		StringBuilder result = new StringBuilder("<customers>\r\n");
		for (Customer customer : customerList) {
			result.append(customer.toXMLString() + "\r\n");
		}
		return result.append("</customers>\r\n");
	}
	
	private StringBuilder getCustomersAsLine(Set<Customer> customerList) {
		StringBuilder result = new StringBuilder("id\tname\tsex\tbirthday\temail\r\n");
		for (Customer customer : customerList) {
			result.append(customer.toString() + "\r\n");
		}
		return result;
	}

}
